package com.ucampus.dao;

import com.ucampus.entity.Article;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;


import java.util.List;

public interface ArticleDao {
    @Select("select * from article")
    List<Article> getAll();

    @Delete("<script>" +
            "delete from article where id in " +
            "<foreach collection='list' item='id' open='(' separator=',' close=')'>#{id}</foreach>" +
            "</script>")
    int delete(List<Integer> list);

    // 用户上传自己的博客内容
    @Insert("INSERT INTO article (userId, username, content, time, img, likes) VALUES (#{userId}, #{username}, #{content}, #{time}, #{img}, #{likes})")
    int insert(Article article);

    @Select("SELECT * FROM article WHERE username LIKE CONCAT('%', #{keyword}, '%') OR content LIKE CONCAT('%', #{keyword}, '%')")
    List<Article> searchByKeyword(String keyword);

    // 通过 userId 查询帖子：
    @Select("SELECT * FROM article WHERE userId = #{userId}")
    List<Article> getArticlesByUserId(long userId);
}
